home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / private / pdcsetsc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  11.4 KB  |  522 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #define    CURSES_LIBRARY    1
  20. #include <curses.h>
  21.  
  22. #ifdef PDCDEBUG
  23. char *rcsid_PDCsetsc  = "$Id$";
  24. #endif
  25.  
  26. /*man-start*********************************************************************
  27.  
  28.   PDC_set_80x25()    - force a known screen state: 80x25 text mode.
  29.  
  30.   PDCurses Description:
  31.      This is a private PDCurses function.
  32.  
  33.      Forces the appropriate 80x25 alpha mode given the display adapter.
  34.  
  35.      Since we currently do not support changing the virtual console size,
  36.      this routine is a NOP under Flexos.
  37.  
  38.   PDCurses Return Value:
  39.      This function returns OK upon success otherwise ERR is returned.
  40.  
  41.   PDCurses Errors:
  42.      No errors are defined for this routine.
  43.  
  44.   Portability:
  45.      PDCurses    int    PDC_set_80x25( void );
  46.  
  47. **man-end**********************************************************************/
  48.  
  49. int    PDC_set_80x25(void)
  50. {
  51. #if defined( OS2 ) && !defined( EMXVIDEO )
  52.     VIOMODEINFO modeInfo={0};
  53. #endif
  54.  
  55. #ifdef PDCDEBUG
  56.     if (trace_on) PDC_debug("PDC_set_80x25() - called\n");
  57. #endif
  58.  
  59. #ifdef    FLEXOS
  60.     return( OK );
  61. #endif
  62.  
  63. #ifdef    DOS
  64.     switch (_cursvar.adapter)
  65.     {
  66.     case _CGA:
  67.     case _EGACOLOR:
  68.     case _EGAMONO:
  69.     case _VGACOLOR:
  70.     case _VGAMONO:
  71.     case _MCGACOLOR:
  72.     case _MCGAMONO:
  73.         regs.h.ah = 0x00;
  74.         regs.h.al = 0x03;
  75.         int86(0x10, ®s, ®s);
  76.         break;
  77.     case _MDA:
  78.         regs.h.ah = 0x00;
  79.         regs.h.al = 0x07;
  80.         int86(0x10, ®s, ®s);
  81.     default:
  82.         break;
  83.     }
  84.     return( OK );
  85. #endif
  86.  
  87. #ifdef    OS2
  88. # ifdef EMXVIDEO
  89.     return( OK );
  90. # else
  91.     modeInfo.cb = sizeof(modeInfo);
  92.     /* set most parameters of modeInfo */
  93.     VioGetMode(&modeInfo, 0);
  94.     modeInfo.fbType = 1;
  95.     VioSetMode(&modeInfo, 0);
  96. # endif
  97. #endif
  98.  
  99. #ifdef UNIX
  100. /* INCOMPLETE */
  101. #endif
  102. }
  103.  
  104. /*man-start*********************************************************************
  105.  
  106.   PDC_set_cursor_mode()    - Set the cursor start and stop scan lines.
  107.  
  108.   PDCurses Description:
  109.      Sets the cursor type to begin in scan line startrow and end in
  110.      scan line endrow.  Both values should be 0-31.
  111.  
  112.   PDCurses Return Value:
  113.      This function returns OK on success and ERR on error.
  114.  
  115.   PDCurses Errors:
  116.      No errors are defined for this function.
  117.  
  118.   Portability:
  119.      PDCurses    int PDC_set_cursor_mode( int startrow, int endrow );
  120.  
  121. **man-end**********************************************************************/
  122.  
  123. int    PDC_set_cursor_mode( int startrow, int endrow )
  124. {
  125. #ifdef    OS2
  126. # ifndef EMXVIDEO
  127.     VIOCURSORINFO cursorInfo={0};
  128. # endif
  129. #endif
  130.  
  131. #ifdef    FLEXOS
  132.     unsigned short mybuff = 0;
  133. #endif
  134.  
  135. #ifdef PDCDEBUG
  136.     if (trace_on) PDC_debug("PDC_set_cursor_mode() - called: startrow %d endrow %d\n",startrow,endrow);
  137. #endif
  138.  
  139. #ifdef    FLEXOS
  140.     /*
  141.      * Under FLEXOS, this routine translates the input parameters in the
  142.      * following way:
  143.      *
  144.      * startrow --> visible_cursor endrow     -->    cursor type:
  145.      * underline = 0; block = 1;
  146.      *
  147.      * VCWM_CURSOR       0x0100       bit - 8 Cursor off VCWM_BLOCK    
  148.      * 0x0200       bit - 9 Block Cursor    
  149.      *
  150.      */
  151.     retcode = s_getfield(T_VIRCON, VC_MODE, 1L, (void far *) &mybuff, 2L);
  152.     if (retcode < 0L)
  153.         return( ERR );
  154.     if (startrow)
  155.         mybuff &= ~VCWM_CURSOR;
  156.     else
  157.         mybuff |= VCWM_CURSOR;
  158.  
  159.     if (endrow)
  160.         mybuff |= VCWM_BLOCK;
  161.     else
  162.         mybuff &= ~VCWM_BLOCK;
  163.  
  164.     retcode = s_setfield(T_VIRCON, VC_MODE, 1L, (void far *) &mybuff, 2L);
  165.     return( (retcode < 0L) ? ERR : OK );
  166. #endif
  167.  
  168. #ifdef    DOS
  169.     regs.h.ah = 0x01;
  170.     regs.h.ch = (unsigned char) startrow;
  171.     regs.h.cl = (unsigned char) endrow;
  172.     int86(0x10, ®s, ®s);
  173.     return( OK );
  174. #endif
  175.  
  176. #ifdef    OS2
  177. # ifdef EMXVIDEO
  178.     if (endrow <= startrow)
  179.         v_hidecursor();
  180.     else
  181.         v_ctype (startrow, endrow);
  182.     return( OK );
  183. # else
  184.     cursorInfo.yStart = startrow;
  185.     cursorInfo.cEnd = endrow;
  186.     cursorInfo.cx = 1;
  187.     cursorInfo.attr = 0;
  188.     return (VioSetCurType (&cursorInfo, 0) == 0);
  189. # endif
  190. #endif
  191.  
  192. #ifdef UNIX
  193.     return(0); /* this is N/A */
  194. #endif
  195. }
  196.  
  197. /*man-start*********************************************************************
  198.  
  199.   PDC_set_font()    - sets the current font size
  200.  
  201.   PDCurses Description:
  202.      This is a private PDCurses function.
  203.  
  204.      This routine sets the current font size, if the adapter allows
  205.      such a change.
  206.  
  207.   PDCurses Return Value:
  208.      This function returns OK upon success otherwise ERR is returned.
  209.  
  210.   PDCurses Errors:
  211.      It is an error to attempt to change the font size on a "bogus"
  212.      adapter.  The reason for this is that we have a known video
  213.      adapter identity problem.  e.g. Two adapters report the same
  214.      identifying characteristics.
  215.  
  216.      It is also an error to attempt to change the size of the Flexos
  217.      console (as there is currently no support for that).
  218.  
  219.   Portability:
  220.      PDCurses    int    PDC_set_font( int size );
  221.  
  222. **man-end**********************************************************************/
  223.  
  224. int    PDC_set_font(int size)
  225. {
  226. #ifdef    OS2
  227. # ifndef EMXVIDEO
  228.     VIOMODEINFO modeInfo={0};
  229. # endif
  230. #endif
  231.  
  232. #ifdef PDCDEBUG
  233.     if (trace_on) PDC_debug("PDC_set_font() - called\n");
  234. #endif
  235.  
  236. #ifdef    FLEXOS
  237.     return( ERR );
  238. #endif
  239.  
  240. #ifdef    DOS
  241.     if (_cursvar.bogus_adapter)
  242.         return( ERR );
  243.  
  244.     switch (_cursvar.adapter)
  245.     {
  246.     case _CGA:
  247.     case _MDA:
  248.     case _MCGACOLOR:
  249.     case _MCGAMONO:
  250.     case _MDS_GENIUS:
  251.         break;
  252.  
  253.     case _EGACOLOR:
  254.     case _EGAMONO:
  255.         if (_cursvar.sizeable && (_cursvar.font != size))
  256.         {
  257.             switch (size)
  258.             {
  259.             case _FONT8:
  260.                 regs.h.ah = 0x11;
  261.                 regs.h.al = 0x12;
  262.                 regs.h.bl = 0x00;
  263.                 int86(0x10, ®s, ®s);
  264.                 break;
  265.             case _FONT14:
  266.                 regs.h.ah = 0x11;
  267.                 regs.h.al = 0x11;
  268.                 regs.h.bl = 0x00;
  269.                 int86(0x10, ®s, ®s);
  270.                 break;
  271.             default:
  272.                 break;
  273.             }
  274.         }
  275.         break;
  276.  
  277.     case _VGACOLOR:
  278.     case _VGAMONO:
  279.         if (_cursvar.sizeable && (_cursvar.font != size))
  280.         {
  281.             switch (size)
  282.             {
  283.             case _FONT8:
  284.                 regs.h.ah = 0x11;
  285.                 regs.h.al = 0x12;
  286.                 regs.h.bl = 0x00;
  287.                 int86(0x10, ®s, ®s);
  288.                 break;
  289.             case _FONT14:
  290.                 regs.h.ah = 0x11;
  291.                 regs.h.al = 0x11;
  292.                 regs.h.bl = 0x00;
  293.                 int86(0x10, ®s, ®s);
  294.                 break;
  295.             case _FONT16:
  296.                 regs.h.ah = 0x11;
  297.                 regs.h.al = 0x14;
  298.                 regs.h.bl = 0x00;
  299.                 int86(0x10, ®s, ®s);
  300.                 break;
  301.             default:
  302.                 break;
  303.             }
  304.         }
  305.         break;
  306.     default:
  307.         break;
  308.     }
  309.     if (_cursvar.visible_cursor)
  310.         PDC_cursor_on();
  311.     else
  312.         PDC_cursor_off();
  313.     _cursvar.font = PDC_get_font();
  314.     return( OK );
  315. #endif
  316.  
  317. #ifdef    OS2
  318. # ifndef EMXVIDEO
  319.     if (_cursvar.sizeable && (_cursvar.font != size))
  320.     {
  321.            modeInfo.cb = sizeof(modeInfo);
  322.            /* set most parameters of modeInfo */
  323.            VioGetMode(&modeInfo, 0);
  324.            modeInfo.cb = 8;     /* ignore horiz an vert resolution */
  325.                modeInfo.row = modeInfo.vres / size;
  326.            VioSetMode(&modeInfo, 0);
  327.     }
  328.     if (_cursvar.visible_cursor)
  329.         PDC_cursor_on();
  330.     else
  331.         PDC_cursor_off();
  332.     _cursvar.font = PDC_get_font();
  333. # endif
  334.     return( OK );
  335. #endif
  336.  
  337. #ifdef UNIX
  338.     return(OK); /* this is N/A */
  339. #endif
  340. }
  341.  
  342. /*man-start*********************************************************************
  343.  
  344.   PDC_set_rows()    - sets the physical number of rows on screen
  345.  
  346.   PDCurses Description:
  347.      This is a private PDCurses function.
  348.  
  349.      This routine attempts to set the number of rows on the physical
  350.      screen to the passed value.
  351.  
  352.   PDCurses Return Value:
  353.      This function returns OK upon success otherwise ERR is returned.
  354.  
  355.   PDCurses Errors:
  356.      It is an error to attempt to change the screen size on a "bogus"
  357.      adapter.  The reason for this is that we have a known video
  358.      adapter identity problem.  e.g. Two adapters report the same
  359.      identifying characteristics.
  360.  
  361.      It is also an error to attempt to change the size of the Flexos
  362.      console (as there is currently no support for that).
  363.  
  364.   Portability:
  365.      PDCurses    int    PDC_set_rows( int rows );
  366.  
  367. **man-end**********************************************************************/
  368.  
  369. int    PDC_set_rows(int rows)
  370. {
  371. #ifdef    OS2
  372. # ifndef EMXVIDEO
  373.     VIOMODEINFO modeInfo={0};
  374.     USHORT result=0;
  375. # endif
  376. #endif
  377.  
  378. #ifdef PDCDEBUG
  379.     if (trace_on) PDC_debug("PDC_set_rows() - called\n");
  380. #endif
  381.  
  382. #ifdef    FLEXOS
  383.     return( ERR );
  384. #endif
  385.  
  386. #ifdef    DOS
  387.     if (_cursvar.bogus_adapter)
  388.         return( ERR );
  389.  
  390.     switch (_cursvar.adapter)
  391.     {
  392.     case _EGACOLOR:
  393.     case _EGAMONO:
  394.         if (rows < 43)
  395.             PDC_set_font(_FONT14);
  396.         else
  397.             PDC_set_font(_FONT8);
  398.         break;
  399.  
  400.     case _VGACOLOR:
  401.     case _VGAMONO:
  402.         if (rows < 28)
  403.             PDC_set_font(_FONT16);
  404.         else
  405.         if (rows < 50)
  406.             PDC_set_font(_FONT14);
  407.         else
  408.             PDC_set_font(_FONT8);
  409.         break;
  410.  
  411.     case _MCGACOLOR:
  412.     case _MCGAMONO:
  413.     case _MDA:
  414.     case _CGA:
  415.     case _MDS_GENIUS:
  416.     default:
  417.         break;
  418.     }
  419.     _cursvar.font = PDC_get_font();
  420.     LINES = PDC_get_rows();
  421.     COLS = PDC_get_columns();
  422.     return( OK );
  423. #endif
  424.  
  425. #ifdef    OS2
  426. # ifdef EMXVIDEO
  427.     return (ERR);
  428. # else
  429.     modeInfo.cb = sizeof(modeInfo);
  430.     /* set most parameters of modeInfo */
  431.     VioGetMode(&modeInfo, 0);
  432.     modeInfo.fbType = 1;
  433.     modeInfo.row = rows;
  434.     result = VioSetMode(&modeInfo, 0);
  435.     _cursvar.font = PDC_get_font();
  436.     LINES = PDC_get_rows();
  437.     COLS = PDC_get_columns();
  438.     return ((result == 0) ? OK : ERR);
  439. # endif
  440. #endif
  441.  
  442. #ifdef UNIX
  443.     return(0); /* this is N/A */
  444. #endif
  445. }
  446.  
  447. /*man-start*********************************************************************
  448.  
  449.   PDC_set_scrn_mode()    - Set BIOS Video Mode
  450.  
  451.   PDCurses Description:
  452.      Sets the BIOS Video Mode Number ONLY if it is different from
  453.      the current video mode.  This routine is for DOS systems only.
  454.  
  455.   PDCurses Return Value:
  456.      This function returns OK on success and ERR on error.
  457.  
  458.   PDCurses Errors:
  459.      No errors are defined for this function.
  460.  
  461.   Portability:
  462.      PDCurses    int PDC_set_scrn_mode( int new_mode );
  463.  
  464. **man-end**********************************************************************/
  465.  
  466. #if defined( OS2 ) && !defined( EMXVIDEO )
  467. int    PDC_set_scrn_mode(VIOMODEINFO new_mode)
  468. #else
  469. int    PDC_set_scrn_mode(int new_mode)
  470. #endif
  471. {
  472.  
  473. #ifdef    DOS
  474.     int    cur=0;
  475. #endif
  476.  
  477. #ifdef PDCDEBUG
  478.     if (trace_on) PDC_debug("PDC_set_scrn_mode() - called\n");
  479. #endif
  480.  
  481. #ifdef    FLEXOS
  482.     return( OK );
  483. #endif
  484.  
  485. #ifdef    DOS
  486.     cur = (int) PDC_get_scrn_mode();
  487.     if (cur != new_mode)
  488.     {
  489.         regs.h.ah = 0x00;
  490.         regs.h.al = (char) new_mode;
  491.         int86(0x10, ®s, ®s);
  492.     }
  493.     _cursvar.font = PDC_get_font();
  494.     _cursvar.scrnmode = new_mode;
  495.     LINES = PDC_get_rows();
  496.     COLS = PDC_get_columns();
  497.     return( OK );
  498. #endif
  499.  
  500. #ifdef    OS2
  501. # ifdef EMXVIDEO
  502.     return ( OK );
  503. # else
  504.     if (VioSetMode (&new_mode, 0) != 0)
  505.         {
  506.         _cursvar.font = PDC_get_font();
  507.         _cursvar.scrnmode = new_mode;
  508.         LINES = PDC_get_rows();
  509.         COLS = PDC_get_columns();
  510.         return( OK );
  511.         }
  512.     else
  513.         return (ERR);
  514. # endif
  515. #endif
  516.  
  517. #ifdef UNIX
  518.     return(OK); /* this is N/A */
  519. #endif
  520. }
  521.